package com.googlecode.flealancemarket.tapestry.pages;

import com.googlecode.flealancemarket.core.tapestry.SpringBean;
import com.googlecode.flealancemarket.metamodel.Job;
import com.googlecode.flealancemarket.metamodel.User;
import com.googlecode.flealancemarket.service.commands.GetFullUserById;
import com.googlecode.flealancemarket.service.commands.GetJobsForUser;
import com.googlecode.flealancemarket.service.commands.GetUserByUsername;
import com.googlecode.flealancemarket.tapestry.util.Session;
import java.util.Date;
import java.util.List;
import javax.swing.JOptionPane;
import org.apache.tapestry.annotations.ApplicationState;
import org.apache.tapestry.ioc.annotations.Inject;

public class MyJobs {

    @Inject
    @SpringBean("GetJobsForUser")
    private GetJobsForUser getJobsForUser;

    @Inject
    @SpringBean("GetFullUserById")
    private GetFullUserById getFullUserById;

    @ApplicationState
    private Session session;

    private List<Job> jobsList;
    private Job job;

    Object onActivate(){
        if(session.getUserId()==0){
            session.setMessage("You have to be logged in");
            return Categories.class;
        }
        getFullUserById.setId(session.getUserId());
        User user = getFullUserById.execute();
        getJobsForUser.setUser(user);
        jobsList = getJobsForUser.execute();
        return null;
    }

    public boolean getIsActive() {
        return job.getEndingTime().getTime() > new Date().getTime();
    }

    public List<Job> getJobsList() {
        return jobsList;
    }

    public void setJobsList(List<Job> jobsList) {
        this.jobsList = jobsList;
    }

    public Job getJob() {
        return job;
    }

    public void setJob(Job job) {
        this.job = job;
    }

}
